﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Project.Utils
{
    public class EntityUtils
    {
        public static T SetDefuatValueT<T>(T entity, List<object[]> defaultCols)
        {
            if (defaultCols != null && defaultCols.Count > 0)
            {
                Type type = entity.GetType();
                PropertyInfo Property;
                for (int i = 0; i < defaultCols.Count; i++)
                {
                    object[] itemArr = defaultCols[i];
                    Property = type.GetProperty(itemArr[0] + "");
                    if (Property != null && Property.CanWrite)
                    {
                        if (Property.GetValue(entity) == null)
                        {
                            Property.SetValue(entity, itemArr[1]);
                        }
                    }

                }
            }
            return entity;
        }

    }
}
